#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define inf 0xfffffff
using namespace std;
int n, m;
int x, y;
int ans, cnt;
struct node
{
    int x;
    int y;
} p, q, tmp;
queue<node> que;
int next[8][2] = {-1, -1, -1, 0, -1, 1, 0, 1, 0, -1, 1, -1, 1, 0, 1, 1};
int _next[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
char a[25][25];
int vis[25][25], _vis[25][25];
bool check(int x, int y)
{
    if (x < 1 || x > n || y < 1 || y > m)
        return false;
    if (vis[x][y] == 1)
        return false;
    if (a[x][y] != 'X')
        return false;
    return true;
}
void bfs()
{
    while (que.size())
    {
        tmp = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) // 遍历连通块每个点的四个方向
        {
            int xx = tmp.x + _next[i][0];
            int yy = tmp.y + _next[i][1];
            if (xx < 1 || xx > n || yy < 1 || yy > m || a[xx][yy] != 'X') // 符合条件周长+1
                ans++;
        }
        for (int i = 0; i <= 7; i++) // 遍历当前点的8个方向，若有覆盖和条件的点就入队
        {
            int tx = tmp.x + next[i][0];
            int ty = tmp.y + next[i][1];
            if (check(tx, ty))
            {
                q.x = tx;
                q.y = ty;
                que.push(q);
                vis[tx][ty] = 1;
            }
        }
    }
}
int main()
{
    while (~scanf("%d%d", &n, &m))
    {
        scanf("%d%d", &x, &y);
        if (n == 0 && m == 0 && x == 0 && y == 0)
            break;
        for (int i = 1; i <= n; i++)
            scanf("%s", a[i] + 1);
        memset(vis, 0, sizeof(vis));
        memset(_vis, 0, sizeof(_vis));
        if (a[x][y] == 'X') // 判断起点，若为'.',则直接输出-1；
        {
            p.x = x;
            p.y = y;
            que.push(p); // 起点入队，并标记
            vis[x][y] = 1;
            ans = 0;
            bfs();
            printf("%d\n", ans);
        }
        else
        {
            printf("0\n");
        }
    }
    return 0;
}